package servlet.customer;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Customer;
import beans.Info;
import beans.Task;
import service.TaskService;
import service.CustomerService;

@WebServlet("/CustomerServlet")
public class CustomerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public CustomerServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CustomerService service = new CustomerService();

		String page = request.getParameter("page"); // 第几页
		if (page == null)
			page = "1";
		Info<Customer> info = null;
		String id = request.getParameter("id"); // 要查询的id
		if (id != null && !id.equals("")) {
			request.setAttribute("id", id);
			info = service.getCustomerById(id);
		}else {
			info = service.getCustomer(page);
		}

		request.setAttribute("customers", info.list); // 顾客信息列表
		request.setAttribute("page", page);
		request.setAttribute("count", info.count);
		request.getRequestDispatcher("/admin/customer.jsp").forward(request, response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
